package com.kvest.notification_test;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class NotificationTestActivity extends Activity {
    private static final String EXTRA_PARAM = "param";
    private TextView log;
    private NotificationManager notificationManager;
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        log = (TextView) findViewById(R.id.log_tv);

        notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        log.append("created\n");

        String outerPAram = getIntent().getStringExtra(EXTRA_PARAM);
        if (!TextUtils.isEmpty(outerPAram)) {
            log.append("EXTRA_PARAM=" + outerPAram + "\n");
        }
    }

    public void onNotifyClick(View view) {
        sendNotification();
    }

    private void sendNotification() {
        Notification notification = new Notification(R.drawable.icon, "Notification for test", System.currentTimeMillis());
        notification.flags |= Notification.FLAG_AUTO_CANCEL;

        Intent intent = new Intent(getApplicationContext(), NotificationTestActivity.class);
        intent.putExtra(EXTRA_PARAM, "test");
        PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, intent , 0);

        notification.setLatestEventInfo(getApplicationContext(), "Test title", "Fulltext test", pi);

        notification.defaults |= Notification.DEFAULT_VIBRATE;

        notification.number = 3;

        notificationManager.notify(7, notification);

        //finish();
    }

    public void onDeleteClick(View view) {
        notificationManager.cancel(7);
    }

    public void onDeleteAllClick(View view) {
        notificationManager.cancelAll();
    }
}
